<?php    
    $isset = false;
    $hocky = $nam = '';
    if(isset($_POST['mamh']) && isset($_POST['malop']))
    {
        $mamh = $_POST['mamh'];
        $malop = $_POST['malop'];
        $arr = explode('.',$_POST['hocky']);
        $hocky = $arr[0];
        $nam = $arr[1];
        
        $sql = "SELECT * FROM lop WHERE MAMONHOC = '".$mamh."' AND MALOP = '".$malop."' AND HOCKY = $hocky AND NAM = '$nam'";
        $result = mysql_query($sql);
        if(mysql_num_rows($result)!=0){
            $isset = true;
            $row = mysql_fetch_assoc($result);
        }
        
    }
?>
<script type="text/javascript">

    function chon_malop(value)
    {
        var arr = $("#select_hocky").val().split('.');
        hocky = arr[0];
        nam = arr[1];
        
        $.ajax({
            url: "dangkymh/ajax_edit.php",
            type: "POST",
            data: {
                mamh: value,
                hocky: hocky,
                nam: nam,
                action: "get_malop"
                },            
            success: function(result)
            {
                $('#select_malop').html(result);
            },
            error: function()
            {
            }
        });
    }
    
    function chon_monhoc()
    {
        var arr = $("#select_hocky").val().split('.');
        hocky = arr[0];
        nam = arr[1];
        
        $.ajax({
            url: "dangkymh/ajax_edit.php",
            type: "POST",
            data: {
                hocky: hocky,
                nam: nam,
                action: "get_mamh"
                },            
            success: function(result)
            {
                $('#select_mamh').html(result);
                chon_malop($('#select_mamh').val());
            },
            error: function()
            {
            }
        });
    }
</script>

<style>
   .label{background: #247CB9; color: #fff; padding: 5px;}
   .value{width: 350px; background: #FFF2F7; padding: 5px;}
</style>

<div id="function">
    CHỈNH SỬA THÔNG TIN LỚP
</div>

<div id="left" style="margin-left: 10px; padding: 10px;">
    <form name="chinhsua" method="post" action="">
    <table>
        <tr>
            <td class="label"><center>Chọn HK và nhập Mã lớp cần chỉnh sửa</center></td>
        </tr>
        <tr>
            <td  class="value" style="width: 180px;">
                Học kỳ:
                <select name="hocky" id="select_hocky" onclick="chon_monhoc()">
                <?php
                    $today = date("Y-m-d");
                    $sql = mysql_query("SELECT lop.HOCKY, lop.NAM FROM lop, hocky WHERE lop.HOCKY = hocky.HOCKY
                        AND lop.NAM = hocky.NAM AND NGAYBATDAU > '$today' GROUP BY lop.HOCKY, lop.NAM");
                    while($rows = mysql_fetch_assoc($sql)) {
                        echo "<option value='".$rows['HOCKY'].".".$rows['NAM']."'>";
                        echo "HK ".$rows['HOCKY']." - ".$rows['NAM'];
                        echo "</option>";
                    }                                  
                ?>
                </select>
            </td>                  
        </tr>
        
        <tr>
            <td  class="value" style="width: 180px;">
                Mã môn: 
                <select name="mamh" id="select_mamh" onclick="chon_malop(this.value)">
                    <option value="">Chọn mã môn học</option>
                <?php
                    $sql = mysql_query("SELECT MAMONHOC, lop.HOCKY, lop.NAM FROM lop, hocky WHERE lop.HOCKY = hocky.HOCKY
                        AND lop.NAM = hocky.NAM AND NGAYBATDAU > '$today' GROUP BY MAMONHOC");
                    while($rows = mysql_fetch_assoc($sql)) {
                        echo "<option value='".$rows['MAMONHOC']."'>";
                        echo $rows['MAMONHOC'];
                        echo "</option>";
                    }                                  
                ?>
                </select>
            </td>                  
        </tr>
        
        <tr>
            <td  class="value" style="width: 180px;">
                Mã lớp:
                <select name="malop" id="select_malop">
                
                </select>
            </td>
            
            <td><center><input type="submit" value="Chọn" class="s_button" /></center></td>                     
        </tr>
        
        
        <tr><td style="width: 20px;"><div id="loading_"></div></td></tr>
    </table> 
    </form>
</div>   


<div id="function_content">
    <form name="edit_info" method="post" action="dangkymh/ajax_edit.php">
    <center><table>
        <tr>    
            <td class="label">Mã MH: &nbsp; </td>
            <td class="value"><input type="text" name="mamh" value="<?php 
                echo ($isset)? $row['MAMONHOC'].'"' : '"' ;?> />
            </td>
        </tr>
        <tr>
            <td class="label">Mã lớp: </td>
            <td class="value"><input type="text" name="malop" value="<?php
                echo ($isset)? $row['MALOP'].'"' : '"' ;?> />
            </td>
        </tr>
        <tr>
            <td class="label">Học kỳ: </td>
            <td class="value"><input type="text" name="hocky" value="<?php
                echo ($isset)? $row['HOCKY'].'"' : '"' ;?> />
            </td>
        </tr>
        <tr>
            <td class="label">Năm: </td>
            <td class="value"><input type="text" name="nam" value="<?php
                echo ($isset)? $row['NAM'].'"' : '"' ;?> />
            </td>
        </tr>
        <tr>
            <td class="label">Mã GV: </td>
            <td class="value"><input type="text" name="magv" value="<?php
                echo ($isset)? $row['MAGIAOVIEN'].'"' : '" disabled="disable"';?> />
            </td>
        </tr>
        <tr>
            <td class="label">Mã loại: </td>
            <td class="value"><input type="text" name="maloai" value="<?php
                echo ($isset)? $row['MALOAI'].'"' : '" disabled="disable"';?> />
            </td>
        </tr>
        <tr>
            <td class="label">Thứ: </td>
            <td class="value"><input type="text" name="thu" value="<?php 
                echo ($isset)? $row['THU'].'"' : '" disabled="disable"';?> />
            </td>
        </tr>
        <tr>
            <td class="label">Ca: </td>
            <td class="value"><input type="text" name="ca" value="<?php 
                echo ($isset)? $row['CA'].'"' : '" disabled="disable"';?> />
            </td>
        </tr>
        <tr>
            <td class="label">Phòng: </td>
            <td class="value"><input type="text" name="phong" value="<?php 
                echo ($isset)? $row['PHONG'].'"' : '" disabled="disable"';?> />
        </tr>
        <tr>
            <td class="label">Tối đa: </td>
            <td class="value"><input type="text" name="toida" value="<?php 
                echo ($isset)? $row['TOIDA'].'"' : '" disabled="disable"';?> />
        </tr>
        <tr>
            <td class="label">Trạng thái: </td>
            <td class="value"><input type="text" name="trangthai" value="<?php 
                echo ($isset)? $row['TRANGTHAI'].'"' : '" disabled="disable"';?> />
        </tr>
        <tr><td>&nbsp;</td></tr>
        
        <tr>
            <td colspan="2"><center><input type="submit" name="action" value="Update" <?php echo ($isset)?'':'disabled="disable"s'; ?> class="s_button" /></center></td>
        </tr>  
    </table></center>
    </form>   
</div>